package com.kgis.fm.access.common.service.impl;

import java.util.List;

import com.kgis.fm.access.common.callback.GroupingAccessCallback;
import com.kgis.kp.common.util.ReflectionUtil;
import com.kgis.kp.dao.DataAccessObjectConst;
import com.kgis.kp.model.Model;

/**
 *
 * @author zhxiaomiao
 * @version 1.0
 *
 */
public abstract class AbstractDataAccessServiceImpl extends AbstractIbatisAccessServiceImpl {

	protected int numberOfExpressionsUsingInClause = DataAccessObjectConst.MAXIMUM_NUMBER_OF_EXPRESSIONS_USING_IN_CLAUSE;

	protected boolean findByIdsUsingInClause = true;

	protected Class<?> getNamespaceSuperClass(Class<?> clazz) {
		Class<?> genericType = ReflectionUtil.getGenericType(clazz);
		if (Object.class.equals(genericType) && null != clazz.getSuperclass()) {
			return getNamespaceSuperClass(clazz.getSuperclass());
		}
		return genericType;
	}

	/**
	 * 一般用于当in条件参数个数>1000个时,进行分组查询
	 *
	 * @param <T>
	 * @param parameters
	 * @param groupingAccessCallback
	 * @return
	 */
	protected <T extends Model> List<T> groupingFind(long[] parameters, GroupingAccessCallback<T> groupingAccessCallback) {
		return groupingAccessCallback.groupingFind(parameters, this.getNumberOfExpressionsUsingInClause());
	}
	/**
	 * @return the numberOfExpressionsUsingInClause
	 */
	public int getNumberOfExpressionsUsingInClause() {
		return numberOfExpressionsUsingInClause;
	}

	/**
	 * @param numberOfExpressionsUsingInClause
	 *            the numberOfExpressionsUsingInClause to set
	 */
	public void setNumberOfExpressionsUsingInClause(int numberOfExpressionsUsingInClause) {
		this.numberOfExpressionsUsingInClause = numberOfExpressionsUsingInClause;
	}

	/**
	 * @return the findByIdsUsingInClause
	 */
	public boolean isFindByIdsUsingInClause() {
		return findByIdsUsingInClause;
	}

	/**
	 * @param findByIdsUsingInClause
	 *            the findByIdsUsingInClause to set
	 */
	public void setFindByIdsUsingInClause(boolean findByIdsUsingInClause) {
		this.findByIdsUsingInClause = findByIdsUsingInClause;
	}

}
